home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 103 / CD-ROM 103.iso / edu / martianwin / src / fx.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-08-11  |  4.4 KB  |  184 lines

  1. void print_screen(SDL_Surface *surface);
  2.  
  3. #define total_bars 4
  4. struct Cbar
  5. {
  6.     float y;
  7.     int x, w, h;
  8.     int R, G, B;
  9.     float speed;
  10.     int accel;
  11. };
  12. Cbar mbar[total_bars];
  13. #define bar_top_speed 340
  14. #define bar_w screen_w
  15. #define bar_h 10
  16. #define floor 420
  17.  
  18.  
  19. void init_bars()
  20. {
  21.     mbar[0].x=0; mbar[0].y=100; mbar[0].w=bar_w; mbar[0].h=1;
  22.     mbar[0].accel=150; mbar[0].speed=0;
  23.     mbar[0].R=50; mbar[0].G=0; mbar[0].B=0;
  24.     mbar[1].x=0; mbar[1].y=150; mbar[1].w=bar_w; mbar[1].h=1;
  25.     mbar[1].accel=150; mbar[1].speed=0;
  26.     mbar[1].R=0; mbar[1].G=50; mbar[1].B=0;
  27.     mbar[2].x=0; mbar[2].y=200; mbar[2].w=bar_w; mbar[2].h=1;
  28.     mbar[2].accel=150; mbar[2].speed=0;
  29.     mbar[2].R=0; mbar[2].G=0; mbar[2].B=50;
  30.     mbar[3].x=0; mbar[3].y=250; mbar[3].w=bar_w; mbar[3].h=1;
  31.     mbar[3].accel=150; mbar[3].speed=0;
  32.     mbar[3].R=10; mbar[3].G=10; mbar[3].B=10;
  33. }
  34.  
  35. void bar_events(int number)
  36. {
  37.     SDL_Rect bar; //limpiamos la barra en la posicion anterior
  38.     bar.x=mbar[number].x; bar.y=int(mbar[number].y); bar.h=bar_h*2; bar.w=bar_w;
  39.     SDL_FillRect(screen, &bar, SDL_MapRGB(screen->format,0,0,0));
  40.     mbar[number].speed+=mbar[number].accel*dt;
  41.     mbar[number].y+=mbar[number].speed*dt;
  42.     if(mbar[number].y>=(floor-bar_h*2))
  43.     {
  44.     mbar[number].speed=-bar_top_speed;
  45.     }
  46. }
  47.  
  48. void draw_bar(int number)
  49. {
  50.     bar_events(number);
  51.     int x,y;
  52.     int scanpos=int(mbar[number].y);
  53.     SDL_Rect barpos;
  54.     barpos.x=mbar[number].x;
  55.     barpos.y=int(mbar[number].y);
  56.     barpos.w=mbar[number].w;
  57.     barpos.h=mbar[number].h;
  58.     int R=mbar[number].R;
  59.     int G=mbar[number].G;
  60.     int B=mbar[number].B;
  61.     for(y=scanpos; y<scanpos+bar_h; y++)
  62.     {
  63.     barpos.y=y;
  64.     R+=(255/int(bar_h));
  65.     G+=(255/int(bar_h));
  66.     B+=(255/int(bar_h));
  67.     if(R>255) R=255;
  68.     if(G>255) G=255;
  69.     if(B>255) B=255;
  70.     SDL_FillRect(screen, &barpos, SDL_MapRGB(screen->format,R, G, B));
  71.     barpos.y+=((bar_h-1)*2)-(y-scanpos)*2;
  72.     SDL_FillRect(screen, &barpos, SDL_MapRGB(screen->format,R, G, B));
  73.     barpos.y-=((bar_h-1)*2)-(y-scanpos)*2;
  74.     }
  75. }
  76.  
  77. void draw_bars()
  78. {
  79.     int n;
  80.     for(n=0; n<total_bars; n++)
  81.     draw_bar(n);
  82. }
  83.  
  84.  
  85.  
  86. #define star_speed 50
  87. #define total_stars 256
  88. struct Cstar
  89. {
  90.     int x,y;
  91.     int R, G, B;
  92.     int speed;
  93. };
  94. Cstar mstar[total_stars];
  95.  
  96. void init_stars()
  97. {
  98.     int n;
  99.     int speed;
  100.     int R, G, B;
  101.     speed=1;
  102.     for(n=0; n<total_stars; n++)
  103.     {
  104.     if(speed==1) {R=49; G=62; B=71;}
  105.     if(speed==2) {R=86; G=109; B=124;}
  106.     if(speed==3) {R=130; G=162; B=183;}
  107.     if(speed==4) {R=213; G=227; B=237;}
  108.     mstar[n].x=int(rand()%screen_w);
  109.     mstar[n].y=int(rand()%floor);
  110.     mstar[n].R=R; mstar[n].G=G; mstar[n].B=B;
  111.     mstar[n].speed=speed;
  112.     speed++;
  113.     if(speed>4)
  114.         speed=1;
  115.     }
  116. }
  117.  
  118. void draw_stars()
  119. {
  120.     SDL_Rect star;
  121.     star.w=1; star.h=1;
  122.     int n;
  123.  
  124.     for(n=0; n<total_stars; n++)
  125.     {
  126.     star.x=mstar[n].x;
  127.     star.y=mstar[n].y;
  128.     SDL_FillRect(screen, &star, SDL_MapRGB(screen->format,0,0,0));
  129.  
  130.     mstar[n].x+=int((star_speed*mstar[n].speed)*dt);
  131.     if(mstar[n].x>=screen_w)
  132.         mstar[n].x=0;
  133.  
  134.     star.y=mstar[n].y;
  135.     star.x=mstar[n].x;
  136.     SDL_FillRect(screen, &star, SDL_MapRGB(screen->format,mstar[n].R,mstar[n].G,mstar[n].B));
  137.     }
  138. }
  139.  
  140.  
  141. #define particles 2048
  142. #define particle_accel 70
  143. #define particle_max_speed 200
  144. struct Cparticle
  145. {
  146.     float x, y;
  147.     float speed_x, speed_y;
  148.     int R, G, B;
  149. };
  150. Cparticle mparticle[particles];
  151.  
  152. void init_combo_fx(int x, int y, int w, int h)
  153. {
  154.     int n;
  155.     for(n=0; n<particles; n++)
  156.     {
  157.     mparticle[n].x=rand()%w+x;
  158.     mparticle[n].y=rand()%h+y;
  159.     mparticle[n].speed_x=rand()%(particle_max_speed*2)-particle_max_speed;
  160.     mparticle[n].speed_y=rand()%particle_max_speed-particle_max_speed;
  161.     mparticle[n].R=255; mparticle[n].G=255; mparticle[n].B=255;
  162.     }
  163. }
  164.  
  165. void combo_fx()
  166. {
  167.     SDL_Rect partpos;
  168.     partpos.w=2; partpos.h=2;
  169.     int n;
  170.     for(n=0; n<particles; n++)
  171.     {
  172.     if(mparticle[n].speed_x>0) mparticle[n].speed_x-=particle_accel*dt;
  173.     else mparticle[n].speed_x+=particle_accel*dt;
  174.     mparticle[n].speed_y+=particle_accel*dt;
  175.     if(mparticle[n].speed_x>0 && mparticle[n].speed_x>= particle_max_speed) mparticle[n].speed_x= particle_max_speed;
  176.     if(mparticle[n].speed_x<0 && mparticle[n].speed_x<= -particle_max_speed) mparticle[n].speed_x= -particle_max_speed;
  177.     if(mparticle[n].speed_y>=particle_max_speed) mparticle[n].speed_y=particle_max_speed;
  178.     mparticle[n].x+=mparticle[n].speed_x*dt;
  179.     mparticle[n].y+=mparticle[n].speed_y*dt;
  180.     partpos.x=int(mparticle[n].x); partpos.y=int(mparticle[n].y);
  181.     SDL_FillRect(screen, &partpos, SDL_MapRGB(screen->format,mparticle[n].R, mparticle[n].G, mparticle[n].B));
  182.     }
  183. }
  184.